﻿<Window x:Class="Auremo.SettingsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:Auremo"
        Title="Settings - Auremo" MinWidth="700" Width="700" MaxWidth="700" MinHeight="280" Height="530" MaxHeight="975"
        ResizeMode="CanResize"
        Background="{StaticResource WindowBackgroundBrush}"
        Closing="OnClose">
    <Window.Resources>
        <l:IntToBoolConverter x:Key="IntToBoolConverter"/>
        <Style x:Key="TabSettingsLabelStyle" TargetType="Label">
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Width" Value="135"/>
        </Style>
        <Style x:Key="TabVisibilityCheckStyle" TargetType="CheckBox">
            <Setter Property="Content" Value="Is visible"/>
            <Setter Property="IsChecked" Value="True"/>
            <Setter Property="Width" Value="85"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <EventSetter Event="Unchecked" Handler="TabPreferencesSanityCheck"/>
        </Style>
        <Style x:Key="DefaultTabSelectionRadioStyle" TargetType="RadioButton">
            <Setter Property="Content" Value="Is default"/>
            <Setter Property="IsChecked" Value="True"/>
            <Setter Property="GroupName" Value="DefaultMusicCollectionTab"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <EventSetter Event="Checked" Handler="TabPreferencesSanityCheck"/>
        </Style>
    </Window.Resources>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Border Grid.Row="0" BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,0,0,1" Margin="0,0,0,10">
            <TextBlock Style="{StaticResource HeaderStyle}">Auremo Settings</TextBlock>
        </Border>
        <ScrollViewer Style="{StaticResource ScrollViewerStyle}" Grid.Row="1">
            <StackPanel>
                <Grid Height="110">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <DataGrid Name="m_ServerSettings" Style="{StaticResource SettingsDataGridStyle}"
                              ItemsSource="{Binding Path=ServerList.Items}"
                              Grid.RowSpan="3"
                              SelectionChanged="OnServerListSelectionChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Server name or address" Width="4*" Binding="{Binding Path=Hostname}"/>
                            <DataGridTextColumn Header="Port" Width="1*" Binding="{Binding Path=Port}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                    <Button Content="New" Style="{StaticResource ActionButtonStyle}" Grid.Column="1" Grid.Row="1" Margin="5,0,5,0" Click="OnAddServerClicked"/>
                    <Button Content="Delete" Style="{StaticResource ActionButtonStyle}" Grid.Column="1" Grid.Row="2" Margin="5,5,5,0" Click="OnDeleteServerClicked"/>
                </Grid>
                <Grid Margin="0,0,5,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                </Grid>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="Server:" Style="{StaticResource OptionLabelStyle}" Width="50"/>
                    <TextBox Name="m_HostnameEntry" Style="{StaticResource OptionTextBoxStyle}" Width="140" LostFocus="ServerEntryUpdated"/>
                    <Label Content="Port:" Style="{StaticResource OptionLabelStyle}" Width="35" Margin="10,0,0,0"/>
                    <TextBox Name="m_PortEntry" Style="{StaticResource OptionTextBoxStyle}" Width="60" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ServerEntryUpdated"/>
                    <Label Content="Password:" Style="{StaticResource OptionLabelStyle}" Width="70" Margin="10,0,0,0"/>
                    <PasswordBox Name="m_PasswordEntry" Style="{StaticResource OptionPasswordBoxStyle}" Width="140" LostFocus="ServerEntryUpdated"/>
                </StackPanel>
                <Border BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="15,10,15,2"/>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="Update server status and user interface every" Style="{StaticResource OptionLabelStyle}" Width="350"/>
                    <TextBox Name="m_UpdateIntervalEntry" Text="500" Style="{StaticResource OptionTextBoxStyle}" Width="50" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="milliseconds (100 - 5000)" Style="{StaticResource OptionLabelStyle}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="Reset connection if the server does not respond within" Style="{StaticResource OptionLabelStyle}" Width="350"/>
                    <TextBox Name="m_NetworkTimeoutEntry" Text="10" Style="{StaticResource OptionTextBoxStyle}" Width="50" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="seconds (1 - 600)" Style="{StaticResource OptionLabelStyle}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="After connection is lost, attempt reconnection every" Style="{StaticResource OptionLabelStyle}" Width="350"/>
                    <TextBox Name="m_ReconnectIntervalEntry" Text="10" Style="{StaticResource OptionTextBoxStyle}" Width="50" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="seconds (0 = never, max 3600)" Style="{StaticResource OptionLabelStyle}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="A mouse wheel tick and the volume keys adjust volume by" Style="{StaticResource OptionLabelStyle}" Width="350"/>
                    <TextBox Name="m_WheelVolumeStepEntry" Text="5" Style="{StaticResource OptionTextBoxStyle}" Width="50" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="percent (0 - 100)" Style="{StaticResource OptionLabelStyle}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <RadioButton Name="m_WheelSongPositioningModeIsPercent" Content="A mouse wheel tick adjusts song position by" IsChecked="True" GroupName="WheelSongPositioningMode" Style="{StaticResource OptionRadioButton}" Width="346"/>
                    <TextBox Name="m_WheelSongPositioningPercentEntry" Text="5" Style="{StaticResource OptionTextBoxStyle}" VerticalAlignment="Center" Width="50" IsEnabled="{Binding ElementName=m_WheelSongPositioningModeIsPercent,Path=IsChecked}" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="percent (0 - 100)" Style="{StaticResource OptionLabelStyle}" IsEnabled="{Binding ElementName=m_WheelSongPositioningModeIsPercent,Path=IsChecked}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <RadioButton Name="m_WheelSongPositioningModeIsSeconds" Content="A mouse wheel tick adjusts song position by" IsChecked="False" GroupName="WheelSongPositioningMode" Style="{StaticResource OptionRadioButton}" Width="346"/>
                    <TextBox Name="m_WheelSongPositioningSecondsEntry" Text="5" Style="{StaticResource OptionTextBoxStyle}" VerticalAlignment="Center" Width="50" IsEnabled="{Binding ElementName=m_WheelSongPositioningModeIsSeconds,Path=IsChecked}" PreviewTextInput="OnNumericOptionPreviewTextInput" LostFocus="ValidateOptions"/>
                    <Label Content="seconds (0 - 1800)" Style="{StaticResource OptionLabelStyle}" IsEnabled="{Binding ElementName=m_WheelSongPositioningModeIsSeconds,Path=IsChecked}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <CheckBox Name="m_EnableVolumeControl" Content="Enable volume control" IsChecked="True" Style="{StaticResource OptionCheckBoxStyle}" Margin="4,6,0,8"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <CheckBox Name="m_UseAlbumArtist" Content="Categorize albums by AlbumArtist tag when available" IsChecked="True" Style="{StaticResource OptionCheckBoxStyle}" Margin="4,6,0,8"/>
                </StackPanel>
                <Border BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="15,2"/>
                <StackPanel Orientation="Horizontal">
                    <Label Content="Sort albums by an artist by" Style="{StaticResource OptionLabelStyle}" Width="349" VerticalAlignment="Top"/>
                    <StackPanel>
                        <RadioButton Name="m_SortAlbumsByDate" Content="Date, then name" IsChecked="True" GroupName="AlbumSortMode" VerticalAlignment="Center" Margin="0,3"/>
                        <RadioButton Name="m_SortAlbumsByDirectory" Content="Directory, then name" IsChecked="False" GroupName="AlbumSortMode" VerticalAlignment="Center" Margin="0,3"/>
                        <RadioButton Name="m_SortAlbumsByName" Content="Name only" IsChecked="False" GroupName="AlbumSortMode" VerticalAlignment="Center" Margin="0,3"/>
                    </StackPanel>
                </StackPanel>
                <Border BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="15,2"/>
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource OptionTextBlockStyle}" Width="345" Height="45">
                            Date formats in the music collection, separated by semicolons.<LineBreak/>
                            Y = year, M = month, D = day, N = arbitrary number.
                        </TextBlock>
                        <TextBox Name="m_DateFormatsEntry" Text="YYYY;YYYY.N;YYYY.NN" Style="{StaticResource OptionTextBoxStyle}" Width="250" VerticalAlignment="Top" Margin="0,5,0,7"/>
                    </StackPanel>
                </StackPanel>
                <Border BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="15,2"/>
                <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                    <TextBlock Style="{StaticResource OptionTextBlockStyle}" Width="344" VerticalAlignment="Top">
                        Pressing Enter or double-clicking items in the music<LineBreak/>
                        collection
                    </TextBlock>
                    <StackPanel>
                        <RadioButton Name="m_SendToPlaylistMethodAppend" Content="Adds the selected items to the end of the playlist" IsChecked="True" GroupName="SendToPlaylistMethod" VerticalAlignment="Center" Margin="0,3"/>
                        <RadioButton Name="m_SendToPlaylistMethodAddAsNext" Content="Adds the items after the current item on the playlist" IsChecked="False" GroupName="SendToPlaylistMethod" VerticalAlignment="Center" Margin="0,3"/>
                        <RadioButton Name="m_SendToPlaylistMethodReplaceAndPlay" Content="Replaces playlist with the items and starts playback" IsChecked="False" GroupName="SendToPlaylistMethod" VerticalAlignment="Center" Margin="0,3"/>
                    </StackPanel>
                </StackPanel>
                <Border BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="15,2"/>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="345"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label Content="Music collection tab preferences"/>
                    <StackPanel Grid.Column="1" Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Quick search tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_QuickSearchTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_QuickSearchTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}" IsChecked="True"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Advanced search tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_AdvancedSearchTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_AdvancedSearchTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Artist list tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_ArtistListTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_ArtistListTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Artist tree tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_ArtistTreeTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_ArtistTreeTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Genre list tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_GenreListTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_GenreListTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Genre tree tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_GenreTreeTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_GenreTreeTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Filesystem tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_FilesystemTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_FilesystemTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Streams tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_StreamsTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_StreamsTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="Playlists tab" Style="{StaticResource TabSettingsLabelStyle}"/>
                            <CheckBox Name="m_PlaylistsTabIsVisible" Style="{StaticResource TabVisibilityCheckStyle}"/>
                            <RadioButton Name="m_PlaylistsTabIsDefault" Style="{StaticResource DefaultTabSelectionRadioStyle}"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </ScrollViewer>
        <Border Grid.Row="2" BorderBrush="{StaticResource SeparatorBorderBrush}" BorderThickness="0,1,0,0" Margin="0,5,0,0">
            <DockPanel LastChildFill="False"  VerticalAlignment="Bottom">
                <Button Name="m_CancelButton" IsCancel="True" Style="{StaticResource ActionButtonStyle}" Content="Cancel" Width="90" Margin="4" DockPanel.Dock="Right" Click="OnCancelClicked"/>
                <Button Name="m_RevertButton" Style="{StaticResource ActionButtonStyle}" Content="Revert" Width="90" Margin="4" DockPanel.Dock="Right" Click="OnRevertClicked"/>
                <Button Name="m_ApplyButton" Style="{StaticResource ActionButtonStyle}" Content="Apply" Width="90" Margin="4" DockPanel.Dock="Right" Click="OnApplyClicked"/>
                <Button Name="m_OKButton" IsDefault="True" Style="{StaticResource ActionButtonStyle}" Content="OK" Width="90" Margin="4" DockPanel.Dock="Right" Click="OnOKClicked"/>
            </DockPanel>
        </Border>
    </Grid>
</Window>
